home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / cuj0696.zip / DWYER.ZIP / GAP.TST / GAPPROBS.C < prev    next >
C/C++ Source or Header  |  1996-02-23  |  1KB  |  32 lines

  1. /* ============ */
  2. /* gapprobs.c    */
  3. /* ============ */
  4. #include <mconf.h>
  5. /* ==================================================================== */
  6. /* CalcGapProbs - Calculates Probabilities Relating to the Gap Test    */
  7. /* ==================================================================== */
  8. /* -------------------------------------------------------------------- */
  9. /* This code reflects the algorithm given by D. E. Knuth, The Art of    */
  10. /* Computer Programming, Vol. 2, Seminumerical Algorithms, Second Ed.,    */
  11. /* Addison-Wesley, Reading (1981), page 61, equation 4.            */
  12. /* -------------------------------------------------------------------- */
  13. void
  14. CalcGapProbs(int  NumLengths, double LoLimit, double HiLimit,
  15.          double *GapProbs)
  16. {
  17.     int     k;
  18.     double  BaseProb, CompProb, NextProb;
  19.  
  20.     BaseProb = HiLimit - LoLimit;
  21.     CompProb = 1 - BaseProb;
  22.     NextProb = BaseProb;
  23.  
  24.     for (k = 0; k < NumLengths-1; ++k)
  25.     {
  26.     GapProbs[k] = NextProb;
  27.     NextProb *= CompProb;        /* p*(1-p)^k */
  28.     }
  29.  
  30.     GapProbs[NumLengths-1] = powi(CompProb, NumLengths-1);
  31. }
  32.